package top.zywork.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.*;
import top.zywork.common.BeanUtils;
import top.zywork.dto.PagerDTO;
import top.zywork.query.UserGoodsCouponQuery;
import top.zywork.security.SecurityUtils;
import top.zywork.service.UserGoodsCouponService;
import top.zywork.vo.ResponseStatusVO;
import top.zywork.vo.PagerVO;
import top.zywork.vo.UserGoodsCouponVO;

/**
 * UserGoodsCouponController控制器类<br/>
 *
 * 创建于2019-08-07<br/>
 *
 * @author http://zywork.top 危锦辉
 * @version 1.0
 */
@RestController
@RequestMapping("/user-goods-coupon")
@Slf4j
public class UserGoodsCouponController extends BaseController {

    private UserGoodsCouponService userGoodsCouponService;

    @GetMapping("admin/multi/{id}")
    public ResponseStatusVO listById(@PathVariable("id") Long id) {
        PagerDTO pagerDTO = userGoodsCouponService.listById(id);
        PagerVO pagerVO = BeanUtils.copy(pagerDTO, PagerVO.class);
        pagerVO.setRows(BeanUtils.copyList(pagerDTO.getRows(), UserGoodsCouponVO.class));
        return ResponseStatusVO.ok("查询成功", pagerVO);
    }

    @GetMapping("admin/all")
    public ResponseStatusVO listAll() {
        PagerDTO pagerDTO = userGoodsCouponService.listAll();
        PagerVO pagerVO = BeanUtils.copy(pagerDTO, PagerVO.class);
        pagerVO.setRows(BeanUtils.copyList(pagerDTO.getRows(), UserGoodsCouponVO.class));
        return ResponseStatusVO.ok("查询成功", pagerVO);
    }

    @PostMapping("admin/all-cond")
    public ResponseStatusVO listAllByCondition(@RequestBody UserGoodsCouponQuery userGoodsCouponQuery) {
        PagerDTO pagerDTO = userGoodsCouponService.listAllByCondition(userGoodsCouponQuery);
        PagerVO pagerVO = BeanUtils.copy(pagerDTO, PagerVO.class);
        pagerVO.setRows(BeanUtils.copyList(pagerDTO.getRows(), UserGoodsCouponVO.class));
        return ResponseStatusVO.ok("查询成功", pagerVO);
    }

    @PostMapping("admin/pager-cond")
    public ResponseStatusVO listPageByCondition(@RequestBody UserGoodsCouponQuery userGoodsCouponQuery) {
        PagerDTO pagerDTO = userGoodsCouponService.listPageByCondition(userGoodsCouponQuery);
        PagerVO pagerVO = BeanUtils.copy(pagerDTO, PagerVO.class);
        pagerVO.setRows(BeanUtils.copyList(pagerDTO.getRows(), UserGoodsCouponVO.class));
        return ResponseStatusVO.ok("查询成功", pagerVO);
    }

    /**
     * 用户查询优惠券信息
     * @param userGoodsCouponQuery
     * @return
     */
    @PostMapping("user/pager-cond")
    public ResponseStatusVO userListPageByCondition(@RequestBody UserGoodsCouponQuery userGoodsCouponQuery) {
        userGoodsCouponQuery.setUserId(SecurityUtils.getJwtUser().getUserId());
        return listPageByCondition(userGoodsCouponQuery);
    }

    @Autowired
    public void setUserGoodsCouponService(UserGoodsCouponService userGoodsCouponService) {
        this.userGoodsCouponService = userGoodsCouponService;
    }
}
